app.controller('FeedbackIndex', function($scope, $http, common){
    $scope.status   = '';
    $scope.listAll  = {page: 1, list: new Array()};
    $scope.listHas  = {page: 1, list: new Array()};
    $scope.listNo   = {page: 1, list: new Array()};
    $scope.object   = {};
    $scope.nFeed    = {};
    $scope.pageHtml = '';

    //初始化JS
    $scope.init_js  = function(){
        //标签页钩子设置
        $('a[data-toggle="tab"]').on('show.bs.tab', function(e){
            var type    = $(this).data('target');
            switch(type){
                case '#list-all': $scope.status     = '';break;
                case '#list-no' : $scope.status     = 0; break;
                case '#list-has': $scope.status     = 1; break;
                default: return false; break;
            }
            $scope.load_data(1);
        });
    }

    //加载数据
    $scope.load_data    = function(page){
        var url     = config.prefix_url+'/Feedback/getList?';
        switch($scope.status){
            case 0: 
                $scope.object  = $scope.listNo;
                var url     = url + '&status=0';
            break;
            case 1:
                $scope.object  = $scope.listHas;
                var url     = url + '&status=1';
            break;

            default:
                $scope.object  = $scope.listAll;
            break;
        }
        url     += '&p='+page;
        
        $http.get(url).success(function(info){
            if(info.code != 1){
                common.dealError(info);
            }else{
                $scope.object.page     = page;
                $scope.object.list     = info.data.list;
                common.startPage($scope.load_data);
                $scope.pageHtml     = info.data.page_html;
                $scope.load_style('stop');
            }
        })
        $scope.load_style('start');
    }

    //详情信息
    $scope.detail   = function(feedId){
        var url     = config.prefix_url+'/Feedback/getDetail?feed_id='+feedId;
        $http.get(url).success(function(info){
            if(info.code != 1){
                common.dealError(info);
            }else{
                $scope.nFeed    = info.data.info;
                $('.modal.feed-detail').modal('show');
            }
            $scope.load_style('stop');
        });
        $scope.load_style('start');
    }

    //处理意见
    $scope.deal     = function(feedId){
        var url     = config.prefix_url+'/Feedback/getDetail?feed_id='+feedId;
        $http.get(url).success(function(info){
            if(info.code != 1){
                common.dealError(info);
            }else{
                $scope.nFeed    = info.data.info;
                $('.modal.feed-deal').modal('show');
            }
            $scope.load_style('stop');
        });
        $scope.load_style('start');
    }

    //提交处理
    $scope.submit_deal  = function(){
        var url     = config.prefix_url+'/Feedback/dealItem?';
        var param   = {
            'feed_id'   : $scope.nFeed.id,
            'reward_score'  : $scope.nFeed.reward_score
        }
        $http.post(url, param).success(function(info){
            if(info.code != 1){
                common.dealError(info);
            }else{
                console.log(info);
            }
            $scope.load_style('stop');
            $scope.load_data($scope.object.page);
            $('.modal.feed-deal').modal('hide');
        });
        $scope.load_style('start');
    }

    //‘加载’样式
    $scope.load_style   = function(type){
        switch(type){
            case 'start':
                $('.title').children('.fa-spinner').css('display', 'inline');
            break;
            case 'stop':
                $('.title').children('.fa-spinner').css('display', 'none');
            break;
        }
    }

    $scope.init_js();
    $scope.load_data(1);
});